/**
 * Created by YF on 2018/7/13.
 */
let rollup =  require("rollup");
let rollupPlugins = require('rollup-load-plugins')();
let gulp =require('gulp');
let plugins = require("gulp-load-plugins")();

gulp.task("createApp.js",async()=>{
    await rollup.rollup({
        input:"./app/app_es6.js",
        plugins:[
            rollupPlugins.babel({
                exclude: 'node_modules/**', babelrc: false,
                presets: [
                    ["es2015", {"modules": false}]
                ],
                plugins: ["transform-runtime","transform-async-to-generator"],
                runtimeHelpers: true
            }),
            rollupPlugins.nodeResolve({jsnext: true, main: true,browser: true}),
            rollupPlugins.commonjs({include: 'node_modules/**'})
        ],
    }).then(res=>{
        res.write({
            format:"es",
            file:"./app/app.js",
            sourceMap: true
        })
    })
});

gulp.task("toAndroid",["createApp.js"],()=>{
    gulp.src("./app/app.js")
        .pipe(gulp.dest("G:/oschina/ZKAppForAS/app/src/main/assets/"));
});

let znXmlUrl = "G:/oschina/zk_1.0/app/src/main/assets";
gulp.task("SoftwareCopyrightEnd",()=>{
    return gulp.src([`${znXmlUrl}/zn/`,`!${znXmlUrl}/zn/index*`,`${znXmlUrl}/*.html`])
        .pipe(plugins.concat("softwareEnd.txt"))
        .pipe(gulp.dest("./software/"))
});
gulp.task("SoftwareCopyrightStart",()=>{
    return gulp.src([`${znXmlUrl}/zn/index.xml`,`${znXmlUrl}/zn/index.js`,`${znXmlUrl}/zn/index-community.xml`,`${znXmlUrl}/zn/index-consult.xml`,`${znXmlUrl}/zn/index-home.xml`,`${znXmlUrl}/zn/index-user.xml`,`${znXmlUrl}/zn/index-user.js`])
        .pipe(plugins.concat("softwareStart.txt"))
        .pipe(gulp.dest("./software/"))
});
gulp.task("SoftwareCopyright",["SoftwareCopyrightStart","SoftwareCopyrightEnd"],()=>{
    gulp.src([`./software/softwareStart.txt`,`./software/softwareEnd.txt`])
        .pipe(plugins.concat("software.txt"))
        .pipe(gulp.dest("./software/"));
});

gulp.task("e62e5",async()=>{
    await rollup.rollup({
        input:"./life/life.js",
        plugins:[
            rollupPlugins.babel({
                exclude: 'node_modules/**', babelrc: false,
                presets: [
                    ["es2015", {"modules": false}]
                ],
                plugins: ["transform-runtime","transform-async-to-generator"],
                runtimeHelpers: true
            }),
            rollupPlugins.nodeResolve({jsnext: true, main: true,browser: true}),
            rollupPlugins.commonjs({include: 'node_modules/**'})
        ],
    }).then(res=>{
        res.write({
            format:"es",
            file:"./life/life_es5.js",
            sourceMap: true
        })
    })
});
gulp.task('default', () => {
    return gulp.src('public/js/*.js')
        .pipe(plugins.babel({
            // exclude: 'node_modules/**', babelrc: false,
            presets: [
                ["es2015", {"modules": false}]
            ],
            plugins: ["transform-runtime","transform-async-to-generator"],
            // runtimeHelpers: true
        }))
        .pipe(gulp.dest('public/javascripts'));
});